﻿
var hdnUserID = $("#hdnUserID").val();


$("#btnLogin").live("click", function (e) {

    var username = $("#user_name").val();
    var password = $("#password").val();

    var userid = hdnUserID;

    if (username == '' && password == '') {
        alert("You have not entered a Username(or Password).");
    }
    else {

        var returnValue = isValidEmailAddress(username);
        if (returnValue == false) {

            if (confirm("If you want to be able to retrieve a lost password in the future, you should use your email address as your username. Click ‘OK’ to continue, or ‘Cancel’ to change your username.")) {

                if (userid != '') {
                    $("#FormWebView").submit();
                }
            }
        }

        else {
            if (userid != '') {
                $("#FormWebView").submit();
            }
        }

    }


});


function success(data) {

    if (data != 0) {

        $("#updateusername").hide();
       
        var obj = data.JsonResult;
        var getuserID = obj[0]["user_id"];
        var getUpdateUsername = obj[0]["UpdateUsername"];
        var getUpdatePassword = obj[0]["UpdatePassword"];
        var getWebSetup = obj[0]["WebSetup"];

        //Update UserName
        if (getUpdateUsername == "noChange") {
            //alert("No change was made to your Username.");
        }
        else if (getUpdateUsername == "failed") {

            $("#updateusername").show();
            $("#updateusername label").html("Sorry, this username is already taken, please enter a different one.");
        }
       //Update Password
        if (getUpdatePassword == "noChange") {
            //alert("No change was made to your Password.");
        }

        if (getUpdateUsername == "successful" && getUpdatePassword == "successful") {
            $("#updateusername").show();
            $("#updateusername label").html("Username and Password updated");
        }
        else if (getUpdateUsername == "successful")
        {
            $("#updateusername").show();
            $("#updateusername label").html("Username updated");
        }
        else if (getUpdatePassword == "successful") {
            $("#updateusername").show();
            $("#updateusername label").html("Password updated");
        }
      

        //Another Case (updateUsernamePassword= "failedUserNotFound")
        if (getUpdatePassword == "failedUserNotFound") {

            $("#updateusername").show();
            $("#updateusername label").html("Account cannot be found. Close and reopen app, and setup a new account.");
        }
    }

    else {

        $("#updateusername").hide();
       
    }
    $("#wait").hide();
    window.scrollTo(0, 0);
}


